<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CaseShow;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CaseShowController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CaseShow(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title')->limit(20);
            $grid->column('description')->limit(40);
            $grid->column('type', '案例类型')->using([
                0 => '财产纠纷案',
                1 => '合同纠纷案',
                2 => '劳动纠纷案'
            ])->label([
                0 => 'green',
                1 => 'yellow',
                2 => 'orange'
            ]);
            $grid->column('happened');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CaseShow(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('cover', '封面图')->image();
            $show->field('description');
            $show->field('content')->unescape();
            $show->field('happened');
            $show->field('type', '案例类型')->using([
                0 => '财产纠纷案',
                1 => '合同纠纷案',
                2 => '劳动纠纷案'
            ])->label();
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CaseShow(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->image('cover', '封面图')->autoUpload()->saveFullUrl();
            $form->textarea('description');
            $form->editor('content');
            $form->datetime('happened');
            $form->radio('type', '案例类型')->options([
                0 => '财产纠纷案',
                1 => '合同纠纷案',
                2 => '劳动纠纷案'
            ])->default(0);

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
